package com.zy.dp.simplefactory.example2;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Factory
{

	public static Api createApi()
	{
		Properties p = new Properties();

		InputStream in = null;
		try
		{

			in = Factory.class.getResourceAsStream("FactoryTest.properties");
			p.load(in);

		}
		catch (IOException e)
		{
			System.out.println("装载工厂配置文件出错了，具体的堆栈信息如下：");

			e.printStackTrace();
		}
		finally
		{

			try
			{
				in.close();
			}
			catch (IOException ex)
			{
				ex.printStackTrace();
			}
		}

		Api api = null;
		try
		{

			api = (Api) Class.forName(p.getProperty("ImplClass")).newInstance();

		}
		catch (InstantiationException e)
		{
			e.printStackTrace();
		}
		catch (IllegalAccessException e)
		{
			e.printStackTrace();
		}
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}

		return api;

	}

}
